﻿using Abp.Auditing;
using Abp.Authorization;
using Mt.Site.Application.Navigation.Dto;
using Mt.Site.Core.Navigations.MenuInfo;
using System.Threading.Tasks;

namespace Mt.Site.Application.Navigation
{
    [DisableAuditing]
    public class ColumnConfigAppService : MtSiteFrontendAppServiceBase, IColumnConfigAppService
    {
        private readonly IMenuInfoManager _menuInfoManager;

        public ColumnConfigAppService(IMenuInfoManager menuInfoManager)
        {
            _menuInfoManager = menuInfoManager;
        }

        [AbpAuthorize]
        public async Task<string> GetCustomConfig(long menuId)
        {
            var entity = await _menuInfoManager.GetConfig(menuId, MenuInfoManager.CustomedConfig);
            return entity?.ExtensionData;
        }
        
        public async Task<string> GetCustomData(long menuId)
        {
            var entity = await _menuInfoManager.GetConfig(menuId, MenuInfoManager.CustomedData);
            return entity?.ExtensionData;
        }
        [AbpAuthorize]
        public async Task<CustomConfigAndDataDto> GetCustomConfigAndData(long menuId)
        {
            var configEntity = await _menuInfoManager.GetConfig(menuId, MenuInfoManager.CustomedConfig);

            var dataEntity = await _menuInfoManager.GetConfig(menuId, MenuInfoManager.CustomedData);

            return new CustomConfigAndDataDto
            {
                CustomConfig = configEntity?.ExtensionData,
                CustomData = dataEntity?.ExtensionData
            };
        }
    }
}
